package models

import (
	"github.com/astaxie/beego/orm"
	_ "github.com/go-sql-driver/mysql"
	"time"
)

// 默认使用驼峰蛇形转换，转换后为blog_user
type BlogUser struct {
	Id   int    `orm:"pk;auto;unique"`
	Url  string `orm:"size(255);null"`
	Name string `orm:"size(255)"`
	Type int8   `orm:"type(tinyint);default(0)"`
}

type BlogCategory struct {
	Id          int    `orm:"pk;auto;unique"`
	UrlName     string `orm:"size(255)"`
	ShowName    string `orm:"size(255)"`
	Describtion string `orm:"size(255);null"`
}

type BlogTag struct {
	Id          int    `orm:"pk;auto;unique"`
	UrlName     string `orm:"size(255)"`
	ShowName    string `orm:"size(255)"`
	Describtion string `orm:"size(255);null"`
}

type PageInfo struct {
	Id          int           `orm:"pk;auto;unique"`
	Cate        *BlogCategory `orm:"rel(fk);null;on_delete(set_null)"`
	Tag         *BlogTag      `orm:"rel(fk);null;on_delete(set_null)"`
	Author      string        `orm:"size(255)"`
	Title       string        `orm:"size(255)"`
	Describtion string        `orm:"size(1024);null"`
	Content     *PageContent  `orm:"rel(one)"`
	AddTime     time.Time     `orm:"type(datetime);auto_now_add;"`
	ViewCount   int           `orm:"size(11);default(0)"`
	Type        int8          `orm:"type(tinyint);size(1);default(0)"`
}

type PageContent struct {
	Id       int       `orm:"pk;auto;unique"`
	EditTime time.Time `orm:"type(datetime);auto_now;"`
	Text     string    `orm:"type(text)"`
}

func init() {

	orm.RegisterModel(new(BlogUser), new(BlogTag), new(BlogCategory), new(PageInfo), new(PageContent))

}
